package com.woniuxy.service01;

import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * @author 佘赛飞
 * @create 2021 -11 -04 5:30 PM
 */
public class SomeServiceTest {
    @Test
    public void test01(){
        //耦合
//        SomeService someService = new SomeServiceImpl();
        SomeService someService = new SomeServiceImpl2();
        someService.doSome();
    }

    @Test
    public void test02(){
        String path= "com/woniuxy/service01/applicationContext.xml";
        //相对路径 类路径 src根目录
        ApplicationContext ac=
                new ClassPathXmlApplicationContext(path);
        SomeService someService = (SomeService)ac.getBean("SomeService");
        someService.doSome();
    }

    @Test
    public void test03(){
        String path="src/applicationContext.xml";
        //行对路径 I/O基本API   当前项目
        ApplicationContext ac=
                new FileSystemXmlApplicationContext(path);
        SomeService someService = (SomeService)ac.getBean("SomeService");
        someService.doSome();
    }

    @Test
    public void test04(){
        String path= "com/woniuxy/service01/applicationContext.xml";
        BeanFactory bf = new XmlBeanFactory(
                new ClassPathResource(path));
        SomeService someService = (SomeService)bf.getBean("SomeService");
        someService.doSome();
    }
}
